﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CROSLAND.BL.BE;
using System.Data.Common;
using System.Data;

namespace CROSLAND.DL.DALC.MSSQL
{
    public class AlmacenDALC : BaseDALC, IAlmacenDALC
    {
       
        public List<GenericBE> listar(string pCodMaterial, string pCodCentro)
        {
            List<GenericBE> listaResult = new List<GenericBE>();

            DbCommand command = dbProvider.GetStoredProcCommand("ZWEB_LISTA_ALMACENES");
            dbProvider.AddInParameter(command, "P_MATNR", DbType.String, pCodMaterial);
            dbProvider.AddInParameter(command, "P_WERKS2", DbType.String, pCodCentro);

            string charSep = ParametroDALC.getParamValueStatic("charSep");

            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    GenericBE entity = new GenericBE();
                    
                    entity.Codigo = dr["LGORT"].ToString();

                    entity.Descripcion = (dr["WERKS"].ToString() != string.Empty ? dr["WERKS"].ToString() 
                        + charSep : "") + dr["LGORT"].ToString() + charSep + dr["LGOBE"].ToString();
                    
                    listaResult.Add(entity);
                }
            }

            return listaResult;
            
        }
        
    }
}
